﻿using KmSql.Shared;
using KmSql.SqlServer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KmSql
{
    public class KmSqlBuilder
    {
        DbType DbType;
        string ConnectionString;

        public KmSqlBuilder UseDbConnection(DbType dbType, string connectionString)
        {
            if (!Enum.IsDefined(typeof(DbType), dbType))
                throw new Exception("【KmSql】：DbType enum value error.");
            if (string.IsNullOrWhiteSpace(connectionString))
                throw new Exception("【KmSql】：ConnectionString value can not be null.");
            DbType = dbType;
            ConnectionString = connectionString;
            return this;
        }

        public IKmSql Build()
        {
            IKmSql kmSql = DbType switch
            {
                DbType.SqlServer => new SqlServerProvider(ConnectionString),
                _ => throw new Exception("【KmSql】：This DbType is not supported.")
            };
            return kmSql;
        }
    }
}
